package com.project.springboot.lock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * description: 计数器
 * @author 朱正磊
 * @date 2025-06-05 11:04:06
 */
public class CounterF {

    private final Lock lock = new ReentrantLock();

    private Integer count = 0;

    public void add() {
        lock.lock();
        try {
            count++;
            System.out.println("线程 = " + Thread.currentThread().getName() + ", count = " + count);
        } finally {
            lock.unlock();
        }
    }

    public Integer getCount() {
        return count;
    }

}
